<%@ page import="java.util.Calendar" %>
<%@ page import="java.util.Date" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="ru.niir.goodfil.ui.StorekeeperOrdersBean" %>
<%@ page import="ru.niir.goodfil.db.Order" %>
<%@page contentType="text/html" %>
<%@page pageEncoding="UTF-8" %>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="f" uri="http://java.sun.com/jsf/core" %>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html" %>
<%@taglib prefix="a4j" uri="http://richfaces.org/a4j" %>
<%@taglib prefix="rich" uri="http://richfaces.org/rich" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Goodwill - Заказы</title>
    <link rel="stylesheet" href="resources/css/main.css"/>

    <%--
        <script type="text/javascript" src="resources/js/fixedtableheader.js"></script>
    --%>
    <script type="text/javascript">
        function PrintContent()
        {
            var DocumentContainer = document.getElementById('modalPrint');
            var WindowObject = window.open("", "PrintWindow",
                    "width=750,height=650,top=50,left=50,toolbars=no,scrollbars=yes,status=no,resizable=yes");
            WindowObject.document.writeln(DocumentContainer.innerHTML);
            WindowObject.document.close();
            WindowObject.focus();
            WindowObject.print();
            WindowObject.close();
        }
    </script>
    <style type="text/css">
        .rich-table-subheadercell-rotate {
            -webkit-transform: rotate(-90deg);
            -moz-transform: rotate(-90deg);
            -o-transform: rotate(-90deg);
            -ms-transform: rotate(-60deg);
            filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=1);
            white-space: normal;
            height: 100px;
            width: 2px;
            align:right;
        }

        .rich-table-subheadercell {
            white-space: normal;
            height: 120px;
        }

        td{
            height: 20px;
        }

        th{
            height: 100px;
        }

    </style>
</head>
<body>
<f:view>

<a4j:form id="jsForm" prependId="false">
    <a4j:jsFunction name="storekeepOrder" action="#{StorekeeperOrdersBean.storekeepOrder}" limitToList="true">
        <a4j:actionparam assignTo="#{StorekeeperOrdersBean.storekeepOrder_orderId}"/>
    </a4j:jsFunction>
    <a4j:jsFunction name="refresh" action="#{StorekeeperOrdersBean.refresh}" limitToList="true"
                    oncomplete="document.location='sobrano';"/>
    <a4j:jsFunction name="addOrderId" action="#{StorekeeperOrdersBean.addOrderId}" limitToList="true">
        <a4j:actionparam assignTo="#{StorekeeperOrdersBean.orderId}"/>
    </a4j:jsFunction>
</a4j:form>


<jsp:include page="parts/version.jsp"/>
<jsp:include page="StorageMenu.jsp"/>

<h:form id="hForm" prependId="false">
<jsp:include page="messages.jsp"/>
<jsp:include page="status.jsp"/>

    <h:panelGroup id="links" layout="block" styleClass="">
        <a4j:commandLink value="Обновить" onclick="refresh();" style="margin-top: 10px; margin-left: 10px; font-size: 1.5em;"/>
    </h:panelGroup>

<h:panelGroup layout="block" styleClass="" style="padding:5px">
    <h2 align="left">Собрано, готово к отправке</h2>
    <rich:dataTable id="odrdersForOutput"
                    value="#{StorekeeperOrdersBean.ordersFromOutPool}"
                    var="order"
                    rowKeyVar="row"
                    bgcolor="#FFFFFF">

        <rich:column>
            <f:facet name="header">
                <h:outputText value="№"/>
            </f:facet>
            <h:outputText value="#{row + 1}. "/>
        </rich:column>

        <rich:column rendered="false">
            <f:facet name="header">
                <h:outputText value="Заказы"/>
            </f:facet>
            <h:outputLink value="#" onclick="storekeepOrder(#{order.id})">
                <h:outputText value="открыть"/>
            </h:outputLink>
        </rich:column>

        <rich:column>
            <f:facet name="header">
                <h:outputText value="Номер ИС"/>
            </f:facet>
            <h:outputText value="#{order.id}" style="#{order.deliveryDateIsInPast ? 'color:red':''}"/>
        </rich:column>

        <rich:column>
            <f:facet name="header">
                <h:outputText value="Менеджер"/>
            </f:facet>
            <h:outputText value="#{order.manager.fio}" style="#{order.deliveryDateIsInPast ? 'color:red':''}"/>
        </rich:column>

        <rich:column>
            <f:facet name="header">
                <h:outputText value="Счет 1С"/>
            </f:facet>
            <h:outputText value="#{order.c1Num}" style="#{order.deliveryDateIsInPast ? 'color:red':''}"/>
        </rich:column>

        <rich:column>
            <f:facet name="header">
                <h:outputText value="Дата создания"/>
            </f:facet>
            <h:outputText value="#{order.creationDateAsString}" style="#{order.deliveryDateIsInPast ? 'color:red':''}"/>
        </rich:column>

        <rich:column>
            <f:facet name="header">
                <h:outputText value="Дата отгрузки"/>
            </f:facet>
            <h:outputText value="#{order.deliveryDateAsString}" style="#{order.deliveryDateIsInPast ? 'color:red':''}"/>
        </rich:column>

        <rich:column>
            <f:facet name="header">
                <h:outputText value="Дата сборки"/>
            </f:facet>
            <h:outputText value="#{order.assemblyDateAsString}" style="#{order.deliveryDateIsInPast ? 'color:red':''}"/>
        </rich:column>

        <rich:column filterBy="#{order.client.companyName}" sortable="true" sortBy="#{order.client.companyName}" filterEvent="onblur">
            <f:facet name="header">
                <h:outputText value="Клиент"/>
            </f:facet>
            <h:outputText value="#{order.client.companyName}" style="#{order.deliveryDateIsInPast ? 'color:red':''}"/>
        </rich:column>

        <rich:column>
            <f:facet name="header">
                <h:outputText value="Статус клиента"/>
            </f:facet>
            <h:outputText value="#{order.client.clientStateAsString}" style="#{order.deliveryDateIsInPast ? 'color:red':''}"/>
        </rich:column>

        <rich:column sortable="true" sortBy="#{order.factSum}">
            <f:facet name="header">
                <h:outputText value="Сумма заказа"/>
            </f:facet>
            <h:outputText value="#{order.factSumAsString}" style="#{order.deliveryDateIsInPast ? 'color:red':''}"/>
        </rich:column>

        <rich:column>
            <f:facet name="header">
                <h:outputText value="Оветственный за сборку"/>
            </f:facet>
            <h:outputText value="#{order.storekeeper.fio}" style="#{order.deliveryDateIsInPast ? 'color:red':''}"/>
        </rich:column>

        <rich:column>
            <f:facet name="header">
                <h:outputText value="Тип доставки"/>
            </f:facet>
            <h:outputText value="#{order.deliveryTypeAsString}" style="#{order.deliveryDateIsInPast ? 'color:red':''}"/>
        </rich:column>

        <f:facet name="footer">
            <rich:columnGroup>
                <rich:column/>
                <rich:column/>
                <rich:column/>
                <rich:column/>
                <rich:column/>
                <rich:column/>
                <rich:column/>
                <rich:column/>
                <rich:column/>
                <rich:column>
                    <h:outputText value="Итого: #{StorekeeperOrdersBean.ordersForOutSum}"/>
                </rich:column>
                <rich:column/>
                <rich:column/>
            </rich:columnGroup>
        </f:facet>
    </rich:dataTable>

</h:panelGroup>

</h:form>
</f:view>
</body>
</html>
